package com.example.shop_2210

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.webkit.WebChromeClient
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.core.view.isVisible
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.base.mvvm.BaseViewActivity
import com.example.shop_2210.databinding.ActivityWebBinding

@Route(path = "/app/WebActivity")
class WebActivity : BaseViewActivity<ActivityWebBinding>() {
    @Autowired
    @JvmField
    var url = ""
    override fun initData() {
    }

    override fun initView() {
        ARouter.getInstance().inject(this)

        binding.wv.loadUrl(url)//显示内容
        binding.wv.webViewClient = WebViewClient()//显示在APP内部
        val webChromeClient = object:WebChromeClient(){
            override fun onProgressChanged(view: WebView?, newProgress: Int) {
                super.onProgressChanged(view, newProgress)
                if(newProgress==100){
                    //进度条消失
                    binding.pb.isVisible = false
                }else{
                    binding.pb.progress = newProgress
                }
            }
        }
        binding.wv.webChromeClient = webChromeClient
    }

    override fun getLayout(): Int = R.layout.activity_web

}